﻿using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Data.OleDb;
using System.Data;
using System.Linq;

namespace Project
{
    partial class Form1
    {

        private void InitTestWindow()
        {
            // 
            // MasAnswer
            //
            MasAnswer = new System.Windows.Forms.RadioButton[4];
            for (int i = 0; i < 4; i++)
            {
                MasAnswer[i] = new System.Windows.Forms.RadioButton();
                this.panel3.Controls.Add(this.MasAnswer[i]);
            }
            for (int i = 0; i < 4; i++)
            {
                this.MasAnswer[i].Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                this.MasAnswer[i].Location = new System.Drawing.Point(390, 111 + i * 40);
                this.MasAnswer[i].Name = "answer" + i.ToString();
             //   this.MasAnswer[i].Size = new System.Drawing.Size(284, 34);
                this.MasAnswer[i].Size = new System.Drawing.Size(500, 34);
                this.MasAnswer[i].TabIndex = 2;
                this.MasAnswer[i].Text = "Вариант ответа " + i.ToString();
                this.MasAnswer[i].UseVisualStyleBackColor = true;
                this.MasAnswer[i].CheckedChanged += new System.EventHandler(this.MasAnswer_CheckedChanged);
            }

            /////////////////////////////////////////
            this.panel3.Controls.Add(this.TrueAns);
            this.panel3.Controls.Add(this.Question);
            this.panel3.Controls.Add(this.TestPicture);
            this.panel3.Controls.Add(this.GiveAns);
        }

        private void InitStatLabel()
        {
        //    Question.MaximumSize.Width = panel3.Width - 10 + 386;
            StatLabel = new System.Windows.Forms.Button[15];
            for (int i = 0; i < 15; i++)
            {
                StatLabel[i] = new System.Windows.Forms.Button();
                this.panel1.Controls.Add(this.StatLabel[i]);
            }

            int w_st = (panel1.Width - Date.Width - 5 * 15) / 15;

            for (int i = 0; i < 15; i++)
            {
                this.StatLabel[i].Font = new System.Drawing.Font("Modern No. 20", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                this.StatLabel[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                this.StatLabel[i].Location = new System.Drawing.Point(this.panel3.Location.X + 5 * i + w_st * i, 5);
                this.StatLabel[i].Name = i.ToString();
                this.StatLabel[i].Size = new System.Drawing.Size(w_st, 50);
                this.StatLabel[i].TabIndex = i;
                this.StatLabel[i].Text = (i + 1).ToString();
                //this.StatLabel[i].
                this.StatLabel[i].BackColor = System.Drawing.Color.GhostWhite;
                this.StatLabel[i].ForeColor = System.Drawing.Color.Black;
            }

            this.StatLabel[0].BackColor = System.Drawing.Color.Blue;
            this.StatLabel[0].ForeColor = System.Drawing.Color.White;
        }

        private void ShowDate()
        {
            String month = "";
            switch (DateTime.Now.Month)
            {
                case 1: month = " января "; break;
                case 2: month = " февраля "; break;
                case 3: month = " марта "; break;
                case 4: month = " апреля "; break;
                case 5: month = " мая "; break;
                case 6: month = " июня "; break;
                case 7: month = " июля "; break;
                case 8: month = " августа "; break;
                case 9: month = " сентября "; break;
                case 10: month = " октября "; break;
                case 11: month = " ноября "; break;
                case 12: month = " декабря "; break;
            }
            Date.Text = DateTime.Now.Day.ToString() + month + DateTime.Now.Year.ToString() + "г.";
          
        }

        private void ShowPdf()
        {
           // string str  = Directory.GetCurrentDirectory().ToString();
            axFoxitReaderOCX1.OpenFile("E:\\theory.pdf");
            button1.BringToFront();
           // webBrowser1.Visible = false;
         //   webBrowser1.Navigate(@"E:\theory.pdf");
            //webBrowser1.Navigate(@"..\..\..\theory.pdf");
        }

        private void InitBD()
        {
            String strConn;
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\micro.mdb";
            OleDbConnection con = new OleDbConnection(strConn);

            String strSQL = "Select COUNT(*) FROM tasks";

            DataSet oDS = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(strSQL, con);
            con.Open();
            da.Fill(oDS);
            String numb = oDS.Tables[0].Rows[0][0].ToString();
            int number = Convert.ToInt32(numb);

            MasQuestion = new string [number][];
            for (int i = 0; i < number; i++)
                MasQuestion[i] = new string[5];

            DataSet oDS1 = new DataSet();
            strSQL = "Select * FROM tasks";
            da = new OleDbDataAdapter(strSQL, con);
            da.Fill(oDS1);
            con.Close();

            for (int i = 0; i < number; i++)
                for (int k = 0; k < 5; k++)
                {
                    MasQuestion[i][k] = oDS1.Tables[0].Rows[i][k].ToString();
                }

            AnsRand = new int[4];
            QuestRand = new int[15];
            for (int i = 0; i < 15; i++)
            {
                QuestRand[i] = -1;
            }

            my_rand(QuestRand, 0, 15);

            LoadQuestion(0);
            GiveAns.Enabled = false;
            for (int i = 0; i < MasAnswer.Length; i++)
            {
                MasAnswer[i].Checked = false;
            }
        }

        private void LoadQuestion(int rand)
        {
            my_rand(AnsRand, 1, 5);
            Question.Text = MasQuestion[QuestRand[rand]][0];
            for (int i = 1; i < 5; i++)
                if (MasQuestion[QuestRand[rand]][i][(MasQuestion[QuestRand[rand]][i].Length) - 1] == '*')
                {
                    AnsRight = i;
                    MasQuestion[QuestRand[rand]][i] = MasQuestion[QuestRand[rand]][i].Substring(0, MasQuestion[QuestRand[rand]][i].Length - 1);
                    break;
                }

            for (int i = 0; i < 4; i++)
            {
                this.MasAnswer[i].Text = MasQuestion[QuestRand[rand]][AnsRand[i]];
                if (AnsRand[i] == AnsRight)
                    AnsRight = i;
            }

            Array.Clear(AnsRand, 0, AnsRand.Length);
        }

        private void my_rand(int[] mas_rand, int border1, int border2)
        {
            Random r = new Random(System.Environment.TickCount);
            int l = 0, a;

            while (true)
            {
                a = r.Next(border1, border2);
                if (mas_rand.Contains(a) == false)
                {
                    mas_rand[l] = a;
                    l++;
                }
                if (l == mas_rand.Length)
                    break;
            }
        }
    }
}